﻿
/**
*@description 上传附件表单
*/
Chenxin.UI.UploadLinkageForm = Chenxin.extend(Chenxin.UI.FormCommon, {
    actionUrl: '/service/logic/ShowListLinkage.ashx',
    id: 'divUpload',
    renderTo: 'divUpload',
    jqmWidth: 500,
    createForm: function() {
        return Chenxin.FormCommon.UploadLinkageForm(this.id);
    },
    createComboList: function() {
        var _this = this;
        //用户操作日志类型
        this.cmbitem = new Chenxin.UI.Combo({
            actionUrl: this.actionUrl + '?op=GeItemList',
            containerId: '#divitem',
            name: "ItemId",
            tbxWidth: 90,
            autoLoad: true,
            colNum: 3,
            colWidth: 80,
            hasPage: true,
            pageSize: 15,
            hasSearch: true,
            inModelType: 'all',
            required: true,
            txtModelName: 'ItemName',
            onSelected: function() {
                if (this.getValue() != this.defVal) {
                    if ($('#txtDateTime').val().length > 0) {
                        $('#upload').show();
                        _this.initUpload();
                    }
                    else {
                        this.setValue(this.defVal);
                        alert('请先选择业绩归属');
                    }
                }
                else
                    $('#upload').hide();
            }
        });
        return [this.cmbitem];
    },
    afterGetFormJson: function(json) {
        if (this.filename != undefined) {
            this.additionalParam.filename = this.filename;
            this.additionalParam.savename = this.savename;
        }
    },
    initEvent: function() {
        var _this = this;
        var thisid = '#' + this.id;
        _this.isclick = true;

        $(thisid + '_save').live('click', function() {
            var Adate = $('#txtDateTime').val();
            if (Adate.length < 1)
                alert('请选择业绩归属');
            else
                $("#UploadData").uploadifyUpload();
        });
        $(thisid + '_cancle').live('click', function() {
            _this.hide();
        });
        
    },
    initUpload: function(recordid) {
        var _this = this;
        $('#upload').empty();
        $('#upload').append('<input type="file" id="UploadData" name="UploadData">');
        //上传附件Flash
        $("#UploadData").uploadify({
            uploader: '/js/Plug/uploadify.swf',
            script: '/service/logic/ShowListLinkage.ashx?op=uploaddata',
            cancelImg: '/images/cancel.png',
            buttonImg: '/images/fileupload.png',
            scriptData: { ItemId: _this.cmbitem.getValue(), ItemName: _this.cmbitem.getText(), AchievementDate: $('#txtDateTime').val() },
            auto: false,
            multi: false,
            sizeLimit: 1048576,
            height: 24,
            width: 190,
            fileDesc: '支持格式:xls',
            fileExt: '*.xls',
            wmode: 'transparent',
            onClick: function() {
                _this.isclick = false;
            },
            onSelectCancel: function() {
                _this.isclick = true;
            },
            onComplete: function(event, queueID, fileObj, response, data) {
                if (response) {
                    try {
                        eval("var json=" + response);
                        if (json.success == 1) {
                            alert(json.msg);
                        } else if (json.success == 0) {
                            alert(json.msg);
                        } else {
                            alert(json.msg);
                            window.location.href = Chenxin.loginUrl;
                        }
                    } catch (e) {
                        alert('返回数据格式错误，文件上传失败！');
                    }
                }
            },
            onError: function(event, queueID, fileObj, errorObj) {
                alert("文件:" + fileObj.name + "上传失败(" + errorObj.info + ")");
            },
            onCancel: function(event, queueID, fileObj) {
                _this.isclick = true;
            }
        });
    },
    initComponent: function() {
        Chenxin.UI.UploadLinkageForm.superclass.initComponent.call(this);
    }
});


Chenxin.FormCommon.UploadLinkageForm = function(formID) {
return '<table class="tbl_f"><tr><th style="width:150px;">业绩归属：</th><td><input style="width:120px;" id="txtDateTime" name="AchievementDate" class="inputbox_n fl" type="text" readonly="readonly" onclick="WdatePicker({position:{left:this.getBoundingClientRect().left+1,top:this.getBoundingClientRect().top+22}});" /></td><tr><th>选择项目：</th><td><div id="divitem"></div></td></tr><tr><th>上传附件：</th><td id="upload" style="display:none;"><input type="file" name="UploadData" id="UploadData" /></td></tr><tr><td colspan="2"><input type="hidden"  name="RecordId" /><div style="float:right; margin-right:15px;"><a id="' + formID + '_save" class="btn_n fl" href="#"><span>确定</span></a><a id="' + formID + '_cancle"  class="btn_n fl" href="#"><span>取消</span></a></div></td></tr></table>';
};